<template>
  <div class="orders">
    <div class="search">
      <router-link to="/myhome" class="log" tag="div">
        <img src="../../public/images/img/arrow_left.png" alt="" />
      </router-link>
      <div class="sear">我的订单</div>
      <div class="cai">
        <img src="../../public/images/img/menu.png" alt="" />
      </div>
    </div>
    <div class="content">
      <van-tabs v-model="active" animated sticky swipeable>
        <van-tab title="全部订单">
          <div
            class="order_list_model"
            v-for="item in ordersData"
            :key="item.removTime"
          >
            <div class="title">
              <div class="lf">
                <div class="iconfont icon-shu"></div>
                才华书城
              </div>
              <div class="fr">
                <span v-show="!item.pay">等待付款</span>
                <span v-show="item.pay && item.received">已收货</span>
                <span v-show="item.pay && !item.received" style="color: #ccc"
                  >待收货</span
                >
              </div>
            </div>
            <div class="tips">
              <div class="lf" v-show="!item.pay">
                <div class="text">为确保订单及时发货，请您尽快付款</div>
                <div class="time">{{ item.time }}</div>
              </div>
              <div class="lf" v-show="item.pay">
                <div class="text">
                  {{ item.address[0].province }} {{ item.address[0].city }}
                  {{ item.address[0].county }}
                  {{ item.address[0].addressDetail }}
                </div>
                <div class="time">{{ item.time }}</div>
              </div>
              <div class="fr">
                <span class="iconfont icon-jiantou"></span>
              </div>
            </div>
            <div class="product_list">
              <div class="product_wrap">
                <div class="img">
                  <img :src="item.img[0]" alt="" />
                </div>
                <div class="text">
                  <div class="name">
                    {{ item.name }}
                  </div>
                  <div class="num">x{{ item.num }}</div>
                </div>
              </div>
              <div class="order_list_detail" v-if="!item.pay">
                <span>共{{ item.num }}件商品</span>
                <span>需付款:</span>
                <span class="price"
                  >￥{{ (item.money * item.num).toFixed(2) }}</span
                >
              </div>
              <div class="order_list_btn">
                <div class="pay_cutdown">
                  <span></span>
                  <span class="iconfont icon-shizhong" v-if="!item.pay"></span>
                  <!-- <van-count-down :time="(item.removTime-(+new Date()))" format="DD 天 HH小时mm分ss 秒" /> -->
                  <!-- <div class="time" v-html="Time"></div> -->
                  <!-- <div class="time">
                    <em>{{ h }}</em
                    >小时<em>{{ m }}</em
                    >分<em>{{ s }}</em
                    >秒
                  </div> -->
                  <van-count-down
                    v-if="!item.pay"
                    :time="item.removTime - +new Date()"
                    @finish="removOrders(item.removTime)"
                  >
                    <template #default="timeData">
                      <span class="block">{{ timeData.hours }}</span>
                      <span class="colon">小时</span>
                      <span class="block">{{ timeData.minutes }}</span>
                      <span class="colon">分</span>
                      <span class="block">{{ timeData.seconds }}</span>
                      <span class="colon">秒</span>
                    </template>
                  </van-count-down>

                  <div class="order_list_detail" v-if="item.pay">
                    <span>共{{ item.num }}件商品</span>
                    <span>已付款:</span>
                    <span class="price"
                      >￥{{ (item.money * item.num).toFixed(2) }}</span
                    >
                  </div>
                </div>
                <div class="wait_pay">
                  <div
                    class="iphone"
                    v-show="!item.pay"
                    @click="removOrders(item.removTime)"
                  >
                    取消订单
                  </div>
                  <div class="iphone" v-show="item.received">前往评价</div>
                  <div
                    class="iphone"
                    v-show="item.pay && !item.received"
                    @click="setReceived(item.removTime)"
                  >
                    确认收货
                  </div>
                  <div
                    class="iphone all_red"
                    v-show="!item.pay"
                    @click="toPay(item.removTime)"
                  >
                    立即支付
                  </div>
                </div>
              </div>
            </div>
          </div>
        </van-tab>
        <van-tab title="待付款"> 
          <div
            class="order_list_model"
            v-for="item in ordersData"
            :key="item.removTime"
            v-show="!item.pay"
          >
            <div class="title">
              <div class="lf">
                <div class="iconfont icon-shu"></div>
                才华书城
              </div>
              <div class="fr">
                <span v-show="!item.pay">等待付款</span>
                <span v-show="item.pay && item.received">已收货</span>
                <span v-show="item.pay && !item.received" style="color: #ccc"
                  >待收货</span
                >
              </div>
            </div>
            <div class="tips">
              <div class="lf" v-show="!item.pay">
                <div class="text">为确保订单及时发货，请您尽快付款</div>
                <div class="time">{{ item.time }}</div>
              </div>
              <div class="lf" v-show="item.pay">
                <div class="text">
                  {{ item.address[0] }} {{ item.address[0].city }}
                  {{ item.address[0].county }}
                  {{ item.address[0].addressDetail }}
                </div>
                <div class="time">{{ item.time }}</div>
              </div>
              <div class="fr">
                <span class="iconfont icon-jiantou"></span>
              </div>
            </div>
            <div class="product_list">
              <div class="product_wrap">
                <div class="img">
                  <img :src="item.img[0]" alt="" />
                </div>
                <div class="text">
                  <div class="name">
                    {{ item.name }}
                  </div>
                  <div class="num">x{{ item.num }}</div>
                </div>
              </div>
              <div class="order_list_detail" v-if="!item.pay">
                <span>共{{ item.num }}件商品</span>
                <span>需付款:</span>
                <span class="price"
                  >￥{{ (item.money * item.num).toFixed(2) }}</span
                >
              </div>
              <div class="order_list_btn">
                <div class="pay_cutdown">
                  <span></span>
                  <span class="iconfont icon-shizhong" v-if="!item.pay"></span>
                  <!-- <van-count-down :time="(item.removTime-(+new Date()))" format="DD 天 HH小时mm分ss 秒" /> -->
                  <!-- <div class="time" v-html="Time"></div> -->
                  <!-- <div class="time">
                    <em>{{ h }}</em
                    >小时<em>{{ m }}</em
                    >分<em>{{ s }}</em
                    >秒
                  </div> -->
                  <van-count-down
                    v-if="!item.pay"
                    :time="item.removTime - +new Date()"
                    @finish="removOrders(item.removTime)"
                  >
                    <template #default="timeData">
                      <span class="block">{{ timeData.hours }}</span>
                      <span class="colon">小时</span>
                      <span class="block">{{ timeData.minutes }}</span>
                      <span class="colon">分</span>
                      <span class="block">{{ timeData.seconds }}</span>
                      <span class="colon">秒</span>
                    </template>
                  </van-count-down>

                  <div class="order_list_detail" v-if="item.pay">
                    <span>共{{ item.num }}件商品</span>
                    <span>已付款:</span>
                    <span class="price"
                      >￥{{ (item.money * item.num).toFixed(2) }}</span
                    >
                  </div>
                </div>
                <div class="wait_pay">
                  <div
                    class="iphone"
                    v-show="!item.pay"
                    @click="removOrders(item.removTime)"
                  >
                    取消订单
                  </div>
                  <div class="iphone" v-show="item.received">前往评价</div>
                  <div
                    class="iphone"
                    v-show="item.pay && !item.received"
                    @click="setReceived(item.removTime)"
                  >
                    确认收货
                  </div>
                  <div
                    class="iphone all_red"
                    v-show="!item.pay"
                    @click="toPay(item.removTime)"
                  >
                    立即支付
                  </div>
                </div>
              </div>
            </div>
            
          </div>

          <!--  -->
          <!-- <div class="order_empty">
            <div class="iconfont icon-meiyoudingdan"></div>
            <div class="text">您暂无订单哦～</div>
          </div> -->

          </van-tab>
        <van-tab title="待收货"> <div
            class="order_list_model"
            v-for="item in ordersData"
            :key="item.removTime"
            v-show="item.pay&&!item.received"
          >
            <div class="title">
              <div class="lf">
                <div class="iconfont icon-shu"></div>
                才华书城
              </div>
              <div class="fr">
                <span v-show="!item.pay">等待付款</span>
                <span v-show="item.pay && item.received">已收货</span>
                <span v-show="item.pay && !item.received" style="color: #ccc"
                  >待收货</span
                >
              </div>
            </div>
            <div class="tips">
              <div class="lf" v-show="!item.pay">
                <div class="text">为确保订单及时发货，请您尽快付款</div>
                <div class="time">{{ item.time }}</div>
              </div>
              <div class="lf" v-show="item.pay">
                <div class="text">
                  {{ item.address[0].province }} {{ item.address[0].city }}
                  {{ item.address[0].county }}
                  {{ item.address[0].addressDetail }}
                </div>
                <div class="time">{{ item.time }}</div>
              </div>
              <div class="fr">
                <span class="iconfont icon-jiantou"></span>
              </div>
            </div>
            <div class="product_list">
              <div class="product_wrap">
                <div class="img">
                  <img :src="item.img[0]" alt="" />
                </div>
                <div class="text">
                  <div class="name">
                    {{ item.name }}
                  </div>
                  <div class="num">x{{ item.num }}</div>
                </div>
              </div>
              <div class="order_list_detail" v-if="!item.pay">
                <span>共{{ item.num }}件商品</span>
                <span>需付款:</span>
                <span class="price"
                  >￥{{ (item.money * item.num).toFixed(2) }}</span
                >
              </div>
              <div class="order_list_btn">
                <div class="pay_cutdown">
                  <span></span>
                  <span class="iconfont icon-shizhong" v-if="!item.pay"></span>
                  <!-- <van-count-down :time="(item.removTime-(+new Date()))" format="DD 天 HH小时mm分ss 秒" /> -->
                  <!-- <div class="time" v-html="Time"></div> -->
                  <!-- <div class="time">
                    <em>{{ h }}</em
                    >小时<em>{{ m }}</em
                    >分<em>{{ s }}</em
                    >秒
                  </div> -->
                  <van-count-down
                    v-if="!item.pay"
                    :time="item.removTime - +new Date()"
                    @finish="removOrders(item.removTime)"
                  >
                    <template #default="timeData">
                      <span class="block">{{ timeData.hours }}</span>
                      <span class="colon">小时</span>
                      <span class="block">{{ timeData.minutes }}</span>
                      <span class="colon">分</span>
                      <span class="block">{{ timeData.seconds }}</span>
                      <span class="colon">秒</span>
                    </template>
                  </van-count-down>

                  <div class="order_list_detail" v-if="item.pay">
                    <span>共{{ item.num }}件商品</span>
                    <span>已付款:</span>
                    <span class="price"
                      >￥{{ (item.money * item.num).toFixed(2) }}</span
                    >
                  </div>
                </div>
                <div class="wait_pay">
                  <div
                    class="iphone"
                    v-show="!item.pay"
                    @click="removOrders(item.removTime)"
                  >
                    取消订单
                  </div>
                  <div class="iphone" v-show="item.received">前往评价</div>
                  <div
                    class="iphone"
                    v-show="item.pay && !item.received"
                    @click="setReceived(item.removTime)"
                  >
                    确认收货
                  </div>
                  <div
                    class="iphone all_red"
                    v-show="!item.pay"
                    @click="toPay(item.removTime)"
                  >
                    立即支付
                  </div>
                </div>
              </div>
            </div>
          </div></van-tab>
        <van-tab title="待评价"> <div
            class="order_list_model"
            v-for="item in ordersData"
            :key="item.removTime"
            v-show="item.pay&&item.received"
          >
            <div class="title">
              <div class="lf">
                <div class="iconfont icon-shu"></div>
                才华书城
              </div>
              <div class="fr">
                <span v-show="!item.pay">等待付款</span>
                <span v-show="item.pay && item.received">已收货</span>
                <span v-show="item.pay && !item.received" style="color: #ccc"
                  >待收货</span
                >
              </div>
            </div>
            <div class="tips">
              <div class="lf" v-show="!item.pay">
                <div class="text">为确保订单及时发货，请您尽快付款</div>
                <div class="time">{{ item.time }}</div>
              </div>
              <div class="lf" v-show="item.pay">
                <div class="text">
                  {{ item.address[0].province }} {{ item.address[0].city }}
                  {{ item.address[0].county }}
                  {{ item.address[0].addressDetail }}
                </div>
                <div class="time">{{ item.time }}</div>
              </div>
              <div class="fr">
                <span class="iconfont icon-jiantou"></span>
              </div>
            </div>
            <div class="product_list">
              <div class="product_wrap">
                <div class="img">
                  <img :src="item.img[0]" alt="" />
                </div>
                <div class="text">
                  <div class="name">
                    {{ item.name }}
                  </div>
                  <div class="num">x{{ item.num }}</div>
                </div>
              </div>
              <div class="order_list_detail" v-if="!item.pay">
                <span>共{{ item.num }}件商品</span>
                <span>需付款:</span>
                <span class="price"
                  >￥{{ (item.money * item.num).toFixed(2) }}</span
                >
              </div>
              <div class="order_list_btn">
                <div class="pay_cutdown">
                  <span></span>
                  <span class="iconfont icon-shizhong" v-if="!item.pay"></span>
                  <!-- <van-count-down :time="(item.removTime-(+new Date()))" format="DD 天 HH小时mm分ss 秒" /> -->
                  <!-- <div class="time" v-html="Time"></div> -->
                  <!-- <div class="time">
                    <em>{{ h }}</em
                    >小时<em>{{ m }}</em
                    >分<em>{{ s }}</em
                    >秒
                  </div> -->
                  <van-count-down
                    v-if="!item.pay"
                    :time="item.removTime - +new Date()"
                    @finish="removOrders(item.removTime)"
                  >
                    <template #default="timeData">
                      <span class="block">{{ timeData.hours }}</span>
                      <span class="colon">小时</span>
                      <span class="block">{{ timeData.minutes }}</span>
                      <span class="colon">分</span>
                      <span class="block">{{ timeData.seconds }}</span>
                      <span class="colon">秒</span>
                    </template>
                  </van-count-down>

                  <div class="order_list_detail" v-if="item.pay">
                    <span>共{{ item.num }}件商品</span>
                    <span>已付款:</span>
                    <span class="price"
                      >￥{{ (item.money * item.num).toFixed(2) }}</span
                    >
                  </div>
                </div>
                <div class="wait_pay">
                  <div
                    class="iphone"
                    v-show="!item.pay"
                    @click="removOrders(item.removTime)"
                  >
                    取消订单
                  </div>
                  <div class="iphone" v-show="item.received">前往评价</div>
                  <div
                    class="iphone"
                    v-show="item.pay && !item.received"
                    @click="setReceived(item.removTime)"
                  >
                    确认收货
                  </div>
                  <div
                    class="iphone all_red"
                    v-show="!item.pay"
                    @click="toPay(item.removTime)"
                  >
                    立即支付
                  </div>
                </div>
              </div>
            </div>
          </div></van-tab>
      </van-tabs>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      active: 0,
      ordersData: [],
    
    };
  },
  methods: {

    gteActive(){
      console.log(typeof this.$route.query.id);
      this.active = parseInt(this.$route.query.id)
    },
   
    // getttt() {
    //   setInterval(() => {
    //     this.now = +new Date();
    //   }, 1000);
    // },

    getOrdersData() {
      if (
        JSON.parse(localStorage.getItem("ordersData")) &&
        JSON.parse(localStorage.getItem("ordersData")).length != 0
      ) {
        console.log(JSON.parse(localStorage.getItem("ordersData")));

        this.ordersData = JSON.parse(localStorage.getItem("ordersData"));
      }
    },
    toPay(id) {
      let index = this.ordersData.findIndex((item) => item.removTime == id);
      console.log(index);
      this.ordersData[index].pay = true;
      // this.ordersData[index].received = true
      window.localStorage.setItem(
        "ordersData",
        JSON.stringify(this.ordersData)
      );
    },
    setReceived(id) {
      let index = this.ordersData.findIndex((item) => item.removTime == id);
      console.log(index);
      // this.ordersData[index].pay = true
      this.ordersData[index].received = true;
      window.localStorage.setItem(
        "ordersData",
        JSON.stringify(this.ordersData)
      );
    },
    removOrders(id) {
      let index = this.ordersData.findIndex((item) => item.removTime == id);

      this.ordersData.splice(index, 1);
      window.localStorage.setItem(
        "ordersData",
        JSON.stringify(this.ordersData)
      );
    },
  },
  created() {
    this.gteActive();
    this.getOrdersData();
    
  },
};
</script>

<style lang="scss" scoped>
.orders {
  background-color: #f2f2f2;
  min-height: 100%;
  .content {
    .order_empty{
      margin-top: 30px;
      div{
        text-align: center;
      }
      .text{
        margin-top: 10px;
      }
      .iconfont{
        font-size: 50px;
      }
    }
    .order_list_model {
      margin: 9px 12px;
      background-color: #fff;
      border-radius: 8px;
      height: 100%;
      .title {
        padding: 20px 10px 10px 10px;
        display: flex;
        justify-content: space-between;
        height: 22px;
        .lf {
          font-size: 14px;
          color: #141414;
          display: flex;
          font-weight: 700;
          align-items: center;
          .iconfont {
            font-size: 18px;
            width: 22px;
            text-align: center;
            line-height: 22px;
            height: 22px;
            color: #edd388;
            margin-right: 10px;
            border: 1px solid #edd388;
            border-radius: 50%;
          }
        }
        .fr {
          font-size: 12px;

          color: #ff564d;
        }
      }
      .tips {
        display: flex;
        padding: 5px 10px;
        justify-content: space-between;
        align-items: center;
        .lf {
          .text {
            font-size: 13px;
            color: #414141;
          }
          .time {
            font-size: 12px;
            margin-top: 3px;
            color: #545454;
          }
        }
        .fr {
          font-size: 12px;
          font-weight: 700;
        }
      }
      .product_list {
        .product_wrap {
          height: 77px;
          padding-left: 10px;
          display: flex;
          align-items: flex-end;
          .img {
            width: 62px;
            height: 62px;
            border: 1px solid #e6e6e6;
            border-radius: 6px;
            overflow: hidden;
            img {
              width: 100%;
              display: block;
            }
          }
          .text {
            flex: 1;
            margin-left: 12px;
            .name {
              height: 36px;
              font-size: 13px;
              color: #1e1e1e;
              overflow: hidden;
              text-overflow: ellipsis;
              display: -webkit-box;
              -webkit-line-clamp: 2;
              -webkit-box-orient: vertical;
            }
            .num {
              height: 30px;
              display: flex;
              align-items: flex-end;
              color: #828282;
            }
          }
        }
        .order_list_detail {
          height: 40px;
          padding-right: 10px;
          display: flex;
          justify-content: flex-end;
          align-items: center;
          span {
            color: #1e1e1e;
            margin-right: 10px;
          }
          span.price {
            color: #ff463c;
            font-weight: 600;
            font-size: 16px;
          }
        }
        .order_list_btn {
          padding: 8px 10px 10px 10px;
          display: flex;
          align-items: center;
          justify-content: space-between;
          .pay_cutdown {
            display: flex;
            align-items: center;
            font-size: 12px;
            span {
              color: #ff463c;
            }
            .time {
              color: #030012;
              em {
                color: #ff463c;
                margin: 0 2px;
              }
            }
          }
          .wait_pay {
            display: flex;
            .iphone {
              height: 28px;
              border: 1px solid #ddd;
              border-radius: 28px;
              padding: 0 7px;
              font-size: 13px;
              color: #141414;
              line-height: 28px;
            }
            .iphone.all_red {
              background-color: #ff463c;
              color: #fff;
              border: 1px solid #ff463c;
              margin-left: 10px;
            }
          }
        }
      }
    }
  }
  .search {
    height: 44px;
    display: flex;
    align-items: center;
    border-bottom: 1px solid #d8d8d8;
    position: sticky;
    top: 0;
    background-color: #fff;
    z-index: 2;
    .log {
      width: 40px;
      height: 39.5px;
      display: flex;
      justify-content: center;
      align-items: center;
      img {
        width: 10px;
        height: 17px;
      }
    }
    .cai {
      width: 40px;
      height: 39.5px;
      display: flex;
      justify-content: center;
      align-items: center;
      img {
        width: 21px;
        height: 7px;
      }
    }
    .sear {
      height: 100%;
      flex: 1;
      display: flex;
      align-items: center;
      font-size: 17px;
      justify-content: center;
      color: #333;
      i {
        width: 14px;
        height: 14px;
        display: block;
        margin: 0 9px;
        font-weight: bold;
        color: #767b83;
      }
      span {
        color: #999999;
        font-size: 14px;
      }
    }
  }
}
</style>